/* SharePoint Console Project
 * Http://SharePointConsole.codeplex.com
 * Copyright Jean-Alain Baeyens (2009)
 * Software under Microsoft Reciprocal License (Ms-RL)
 */

using System;

using Microsoft.SharePoint;
using Microsoft.Office.Server.Search.Administration;
using Sharepoint.Console.Commands;

namespace Sharepoint.Console.Search
{
    class GetCrawledPropertyType : BaseCommande
    {
        public override string ShortHelp
        {
            get
            {
                return "Get crawled property type";
            }
        }

        public override string LongHelp
        {
            get
            {
                return "Retrieve the number identifying the internal type of a crawled property. This information is necessary to recreate the same on another server using CreateCrawledProperty statement.";
            }
        }


        public override string Syntax
        {
            get
            {
                return "GetCrawledPropertyType [CrawledPropertyName]";
            }
        }

        public override string Execute(string[] args)
        {
            if (args.Length != 2) return string.Format("Invalide syntax. Use {0}", Syntax);
            
            try
            {
                string crawledPropertyName = args[1];

                SharepointHelper helper = new SharepointHelper();

                CrawledProperty cprop = helper.GetCrawledProperty(this.SharepointConnection, crawledPropertyName);
                if (cprop == null)
                {
                    return "Property not found";
                }
                else
                {
                    return cprop.VariantType.ToString();
                }

            }
            
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
